package org.deng.vertx.springboot;


import io.vertx.core.Vertx;
import lombok.extern.slf4j.Slf4j;
import org.deng.vertx.springboot.config.ProjectProperties;
import org.deng.vertx.springboot.verticle.MainVerticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Author DengLibin
 * @Desc
 * @since 2020/3/13 0013 9:53
 */
@Component
@Order(1) // 执行顺序（如果有多个）
@Slf4j
public class StartRunner implements CommandLineRunner {


    private Vertx vertx;
    private MainVerticle mainVerticle;

    private ProjectProperties projectProperties;
    @Autowired
    public void setMainVerticle(MainVerticle mainVerticle) {
        this.mainVerticle = mainVerticle;
    }

    @Autowired
    public void setVertx(Vertx vertx) {
        this.vertx = vertx;
    }

    @Autowired
    public void setProjectProperties(ProjectProperties projectProperties) {
        this.projectProperties = projectProperties;
    }

    /**
     * 启动完成后的回调方法
     *
     * @param args
     */
    @Override
    public void run(String... args) {
        log.info("======================>启动完成<=====================");
        switch (projectProperties.getEnvEnum()) {
            case TEST:
                log.info("测试环境");
                break;
            case DEV:
                log.info("开发环境");
                break;
            case PRO:
                log.info("生产环境");
                break;
            default:
                break;
        }
        //部署verticle
        vertx.deployVerticle(mainVerticle, res->{
            if(res.succeeded()){
                log.info("部署mainVerticle成功");
            }
        });

    }
}
